package concordia.comp6231.rfmulticast;
import java.util.ArrayList;
import java.util.List;

public class TestExample {
	
	public static void main(String[] args) {
		
		System.out.println("In main");
		
		List<String> aList = new ArrayList<String>();
		/* Testing */
		//aList.add("localhost");
		//aList.add("192.168.1.115");
		//aList.add("132.205.45.240");
		aList.add("132.205.45.228");
		//aList.add("localhost");
		//aList.add("132.205.166.13");
		//aList.add("132.205.164.57");

		Message message = new Message();
		message.put("request_type", "SUSPECT");
		message.put("host_address", "alpha4");
		
		ResultHandler sucess = new ResultHandler() {
			
			@Override
			public void handleResult(Message msg) {
				System.out.println("Success was called!");
			}
		};

		ResultHandler failure = new ResultHandler() {
			
			@Override
			public void handleResult(Message msg) {
				System.out.println("Failure was called!");
			}
		};
		
		ListernerHandler listenHandler = new ListernerHandler() {
			
			@Override
			public Message handleResult(Message msg) {
				System.out.println("Listener was called!");
				
				/* This is an example for u and for me as I can test my code */
				//depending on the received message in your code you will create a new message
				
				Message newResponse = new Message();
				
				newResponse.put("Anykey1", "Anything1");
				newResponse.put("Anykey2", "Anything2");
				newResponse.put("Anykey3", "Anything3");
				
				return newResponse;
			}
		};
		
		RFIFOMulticast rfms = new RFIFOMulticast(aList);
		/* This method is only for me :) */
		rfms.PrintCurrentRecipients();
		
		//rfms.send(4000, message, sucess, failure);
		rfms.listen(4000, listenHandler);
		
		
		/*
		Message response = rfms.synchronosSend(8000, message);
		
		System.out.println("REPLY BACK:\n");
		
		for (String key : response.keySet()) {
			System.out.println("key is: " + key + " and value is: " + response.get(key));
		}
		
		System.out.println();
		*/
		
		//rfms.send(5000, message, sucess, failure);
		//rfms.listen(4000, sucess);
	}

}